package com.ssm.controller;

import com.alibaba.fastjson.JSONArray;
import com.ssm.pojo.Role;
import com.ssm.service.role.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    @Qualifier("roleServiceImpl")
    private RoleService roleService;
    @RequestMapping("/list.json")
    public void roleList(HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("UTF-8");
        List<Role> roleList = roleService.getRoleList();
        String data = JSONArray.toJSONString(roleList);
        PrintWriter writer = response.getWriter();
        response.setContentType("application/json");
        writer.write(data);
        writer.flush();
        writer.close();
    }
}
